package com.mnt.washio.activities;

import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.mnt.washio.R;
import com.mnt.washio.views.CustomFontTextView;

public class WebViewActivity extends BaseActivity {

	private WebView mWebView;
	private String mURL;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_webview);
		initView();
	}

	@SuppressWarnings("deprecation")
	@Override
	protected void initView() {
		super.initView();

		mTvTitle = (CustomFontTextView) findViewById(R.id.tv_title_bar);
		mWebView = (WebView) findViewById(R.id.webview);
		mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
		mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

		mURL = getIntent().getStringExtra("URL");

		mImvTitle.setImageResource(R.drawable.button_back);

		mWebView.loadUrl(mURL);

		mWebView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				mWebView.loadUrl(url);
				return false;
			}
		});
	}

	@Override
	public void finish() {
		if (mWebView.canGoBack()) {
			mWebView.goBack();
		} else {
			super.finish();
		}
	}
}
